import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * Created by David on 2017-07-06.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:beans.xml")
public class Demo {

    @Autowired
    protected DriverManagerDataSource ds;

    @Autowired
    protected Date dd;


    @Autowired
    protected BookMapper bookdao;

    //@Resource(name="bd")
    //protected BookMapper bookdao;

    //@Autowired
    //@Qualifier("bd")
    //protected BookMapper bookdao;

    @Test
    public void jdbc() throws SQLException {
        Connection conn = ds.getConnection();
        System.out.println(conn);
    }


    @Test
    public void aa(){
        System.out.println(dd);

        List<Book> bks = bookdao.query();
        System.out.println(bks.size());
        for(Book b : bks){
            System.out.println(b.getName());
        }
        System.out.println("..................");


        int rr = bookdao.delById(12);
        System.out.println(rr);
        System.out.println("..................");




        Book book = bookdao.queryById(9);
        System.out.println(book);
        System.out.println("..................");


        List<String> bnames = bookdao.queryName();
        System.out.println(bnames.size());
        for(String n : bnames){
            System.out.println(n);
        }
    }
}


